<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="content-section">
    <h2><i class="fas fa-user-md"></i> 个人信息</h2>
    <div class="info-card">
        <div class="info-item">
            <label>工号：</label>
            <span>${doctor.doctorId}</span>
        </div>
        <div class="info-item">
            <label>姓名：</label>
            <span>${doctor.doctorName}</span>
        </div>
        <div class="info-item">
            <label>性别：</label>
            <span>${doctor.doctorGender}</span>
        </div>
        <div class="info-item">
            <label>年龄：</label>
            <span>${doctor.doctorAge}</span>
        </div>
        <div class="info-item">
            <label>电话：</label>
            <span id="phoneDisplay">${doctor.doctorPhone}</span>
        </div>
        <div class="info-item">
            <label>身份证号：</label>
            <span>${doctor.doctorIdCard}</span>
        </div>
        <div class="info-item">
            <label>所属科室：</label>
            <span>${doctor.deptName}</span>
        </div>
        
        <div class="info-actions">
            <button onclick="showEditForm()" class="edit-btn">
                <i class="fas fa-edit"></i>
                修改信息
            </button>
        </div>
    </div>

    <div id="editForm" class="edit-form" style="display: none;">
        <h3>修改个人信息</h3>
        <form id="updateForm" onsubmit="return validateForm()">
            <div class="form-group">
                <label>新手机号码：</label>
                <input type="tel" id="newPhone" name="newPhone" pattern="[0-9]{11}" required>
            </div>
            <div class="form-group">
                <label>新密码：</label>
                <input type="password" id="newPassword" name="newPassword" minlength="6">
            </div>
            <div class="form-group">
                <label>确认新密码：</label>
                <input type="password" id="confirmPassword" name="confirmPassword" minlength="6">
            </div>
            <div class="form-group">
                <label>当前密码：</label>
                <input type="password" id="currentPassword" name="currentPassword" required>
            </div>
            <div class="form-buttons">
                <button type="submit" class="save-btn">
                    <i class="fas fa-check"></i>
                    保存
                </button>
                <button type="button" onclick="hideEditForm()" class="cancel-btn">
                    <i class="fas fa-times"></i>
                    取消
                </button>
            </div>
        </form>
    </div>
</div>

<script>
function showEditForm() {
    document.getElementById('editForm').style.display = 'block';
    document.getElementById('newPhone').value = '${doctor.doctorPhone}';
}

function hideEditForm() {
    document.getElementById('editForm').style.display = 'none';
}

function validateForm() {
    var newPhone = document.getElementById('newPhone').value;
    var newPassword = document.getElementById('newPassword').value;
    var confirmPassword = document.getElementById('confirmPassword').value;
    var currentPassword = document.getElementById('currentPassword').value;
    if (newPassword !== confirmPassword) {
        alert('两次输入的密码不一致！');
        return false;
    }
    
    if (!/^[0-9]{11}$/.test(newPhone)) {
        alert('请输入正确的手机号码！');
        return false;
    }
    
    $.ajax({
        type: 'POST',
        url: '/0201/updateDoctor',
        dataType: 'json',
        data: {
            'newPhone': newPhone,
            'newPassword': newPassword,
            'currentPassword': currentPassword
        },
        success: function(response) {
            if (response.success) {
                alert('更新成功！');
                document.getElementById('phoneDisplay').textContent = newPhone;
                hideEditForm();
                document.getElementById('updateForm').reset();
            } else {
                alert(response.message || '更新失败，请重试！');
            }
        },
        error: function() {
            alert('系统错误，请稍后重试！');
        }
    });
    
    return false;
}
</script> 